﻿using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace WpfApp1.Converters
{
    public class GenderConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string result = string.Empty;
            if (value is int val)
            {
                try
                {
                    if (val == 1) result = "男";
                    if (val == 2) result = "女";
                }
                catch (Exception)
                {
                    // 处理异常
                }
            }
            return result;
        }

        public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int? result = null;
            if (value is string val)
            {
                try
                {
                    if (val == "男") result = 1;
                    if (val == "女") result = 2;
                }
                catch (Exception)
                {
                    // 处理异常
                }
            }
            return result;
        }
    }
}
